package kube

import (
	"context"
	"gitee.com/rthacker/golang_util/pkg/util"
	"gopkg.in/yaml.v3"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
)

func NewConn(c string) {
	config, err := clientcmd.BuildConfigFromFlags("", c)
	if err != nil {
		panic(err.Error())
	}

	clientSet, err := kubernetes.NewForConfig(config)
	//clientSet, err := metrics.NewForConfig(config)
	if err != nil {
		panic(err.Error())
	}
	p, _ := clientSet.CoreV1().Pods("default").List(context.Background(), metav1.ListOptions{})
	b, _ := yaml.Marshal(p.Items)
	var o any
	yaml.Unmarshal(b, &o)
	util.Update("9100", o)

}
